package Servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.ebook.enume.ErrorEnum;
import cn.ebook.service.dao.impl.EbookServiceImpl;
import cn.ebook.util.GsonUtil;
import cn.ebook.util.VoUtil;
import cn.ebook.vo.WebVo;

public class DelServlet extends HttpServlet {
	public EbookServiceImpl e = new EbookServiceImpl();

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		// 设置请求头
		response.setContentType("application/json;charset=utf-8");
		PrintWriter out = response.getWriter();
		// 获取参数
		String idstr = request.getParameter("id");
		Long id = new Long(idstr);

		// 调用servce
		Boolean bo = e.del(id);
		WebVo vo = null;
		if (bo) {
			vo = VoUtil.getSuccess(null);
		} else {
			vo = VoUtil.getErro(ErrorEnum.Ebook_Del_Fail);
		}
		String json = GsonUtil.getJson(vo);
		out.write(json);
		out.flush();
		out.close();
	}

}
